/**
 * Created by YangYan on 2016/5/22.
 */

(function(){
    function Animal() {
        this.name="Animal";
        this.showName=function(){
            console.log(this.name)
        };
        this.call=function(o){
            var temp_name=this.name;
            this.name=o.name;
            o.showName=this.showName;
            this.name=temp_name;
            return o;
        };
    };
    function Cat(){
        this.name="Cat";
    };
    var animal=new Animal();
    var cat=new Cat();
    animal.call(cat,"").showName();
    //-------------------------------------------------
    function Person(name,age){
        this.name=name;
        this.age=age;
        this.sayHello=function(){alert("Hello");}
    };
    function Print(){
        this.funcName="Print";
        this.show=function(){
            var msg=[];
            for(var key in this){
                if(typeof(this[key])!="function"){
                    msg.push([key,":",this[key]].join(""));
                }
            }
          //  console.log((msg.join(" ")));
        };
    };
    function Yang(){
        this.yang="yang";
        this.yan="yan";
    }
    function Student(name,age,grade,school){
        console.log("11111111111111");
        Person.apply(this,arguments);
        Print.apply(this,arguments);
        Yang.apply(this,arguments);
        this.grade=grade;
        this.school=school;
    };
    var p1=new Person("jake",10);
    p1.sayHello();
    var s1=new Student("tom",13,6,"清华小学");
    s1.show();
    console.log(s1);
    s1.show();
    s1.sayHello();
   // alert(s1.funcName);
    //------------------------------------------------

    var arr=[5,7,9,1];//求该数组的最大值
    function getMax(arr){
        var arrlen=arr.length;
        for(var i=0,ret=arr[0];i<arrlen;i++){
            ret=Math.max(ret,arr[i]);
        }
        return ret;
    };
    function getMax2(arr){
        return Math.max.apply(null,arr);
    };
    //------------------------------------------------
    var arr1=[1,3,4];
    var arr2=[3,4,5];
    //把arr2中的元素弄到arr1中去
    //法一：
    var arrlen=arr2.length;
    for(var i=0;i<arrlen;i++){
        arr1.push(arr2[i]);
    };
    //法二：
    Array.prototype.push.apply(arr1,arr2);
    //-------------------------------------------------
    function fatherName(){
        return this.father.name;
    }
    var yuqian={
        father:{
            name:'guodegang'
        }
    };
    var sunwukong={
        father:{
            name:'stone'
        }
    };

    var res=[yuqian,sunwukong].map(function(who){
        return fatherName.call(who);
    });
    //console.log(res);
    //---------------------------------------------------
    var zhangfei={
      father:{
          name:"你管得着么"
      }
    };
    var guanyu={
        father:{
            name:function(){
                return "你猜，你猜，你猜猜"
            }
        }
    };
   var resu= [zhangfei,guanyu].map(function(who){
        var name=fatherName.call(who);
        return Object.prototype.toString.call(name) === "[Object Function]" ? name(): name;
    });
    console.log(resu);

//----------------------------------------------------------------
    function Person1(name,age,love) {
        this.name=name;
        this.age=age;
        this.love=love;
        this.say=function say(){
            console.log("姓名："+name);
        }
    };
    function Student1(name,age){
        Person1.call(this,name,age);//这里name,age指的是属性值，值，值，重要的事情说三次
    };
    var stud=new Student1("name1","222");
    console.log(stud);//所有属性都在，只是love属性的值为undefined






















})()
